home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 May / macformat-024.iso / Shareware City / Developers / TransSkel Pascal 2.5 / TransSkel / Skel ƒ / Skel.p < prev    next >
Encoding:
Text File  |  1994-12-12  |  5.0 KB  |  214 lines  |  [TEXT/PJMM]

  1.  
  2. {    TransSkel demonstration:  Traditional Skel}
  3.  
  4. {    This program mimics the original Skel application:  one sizable,}
  5. {    dragable, non-closable dark gray window, an "About" alert and two}
  6. {    dialogs.  Desk accessories supported.}
  7.  
  8. {    The project should include this file, TransSkel.p (or a library}
  9. {    built from TransSkel.p), Runtime.lib and Interface.lib.}
  10.  
  11. {    27 June 1986        Paul DuBois}
  12. {    1 January 1987    Ωhm Software - port to LS Pascal    }
  13. {    30 December 1987 Ωhm Software - changes for version 2.00 }
  14.  
  15. program Skel;
  16.  
  17.     uses
  18. {$IFC UNDEFINED THINK_PASCAL}
  19.         Memtypes, Quickdraw, OSIntf, ToolIntf, PackIntf, 
  20. {$ENDC}
  21.         TransSkel;
  22.  
  23.     const
  24. {    Resource numbers}
  25.  
  26.         fileMenuRes = 2;        { File menu }
  27.         AboutAlrt = 1000;    { About box }
  28.         theWindRes = 260;        { window }
  29.         reportDlog = 257;        { message dialog box }
  30.         aboutStr = 1;        { message strings }
  31.         rattleStr = 2;
  32.         frightStr = 3;
  33.  
  34. { file menu item numbers }
  35.  
  36.         rattle = 1;
  37.         frighten = 2;
  38.         quit = 4;
  39.  
  40.     type
  41.         EventPtr = ^EventRecord;
  42.  
  43.     var
  44.         theWind: WindowPtr;
  45.  
  46. {    Menu handles.  There isn't any apple menu here, since TransSkel will}
  47. {    be told to handle it itself.}
  48.  
  49.         fileMenu: MenuHandle;
  50.  
  51. {      Dummy Boolean.  This may be used for Memory Management, if desired }
  52.  
  53.         dummy: Boolean;
  54.  
  55. { -------------------------------------------------------------------- }
  56. {                        Menu handling procedures                        }
  57. { -------------------------------------------------------------------- }
  58.  
  59. {    Read a string resource and put into the Alert/Dialog paramtext}
  60. {    values}
  61.  
  62.     procedure SetParamText (strNum: integer);
  63.  
  64.         var
  65.             h: StringHandle;
  66.  
  67.     begin
  68.         h := GetString(strNum);
  69.         HLock(Handle(h));
  70.         ParamText(h^^, '', '', '');
  71.         HUnlock(Handle(h));
  72.     end;
  73.  
  74. {    Handle selection of "About Skel…" item from Apple menu}
  75.  
  76.     procedure DoAbout;
  77.  
  78.         var
  79.             h: StringHandle;
  80.             ignore: integer;
  81.  
  82.     begin
  83.         SetParamText(aboutStr);
  84.         ignore := Alert(aboutAlrt, nil);
  85.     end;
  86.  
  87. {    Put up a dialog box with a message and an OK button.  The message}
  88. {    is stored in the 'STR ' resource whose number is passed as strNum.}
  89.  
  90.     procedure report (strNum: integer);
  91.  
  92.         var
  93.             theDialog: DialogPtr;
  94.             itemHit: integer;
  95.  
  96.     begin
  97.         SetParamText(strNum);
  98.         theDialog := GetNewDialog(Integer(reportDlog), Ptr(nil), WindowPtr(-1));
  99.         ModalDialog(nil, itemhit);
  100.         DisposDialog(theDialog);
  101.     end;
  102.  
  103. {    Process selection from File menu.}
  104.  
  105. {    Rattle, Frighten    A dialog box with message}
  106. {    Quit    Request a halt by calling SkelHalt().  This makes SkelMain}
  107. {            return.}
  108.  
  109.     procedure DoFileMenu (item: integer);
  110.  
  111.     begin
  112.         case item of
  113.             rattle: 
  114.                 Report(rattleStr);
  115.             frighten: 
  116.                 Report(frightStr);
  117.             quit: 
  118.                 SkelWhoa;
  119.             otherwise
  120.                 ;
  121.         end;
  122.     end;
  123.  
  124.  
  125. {    Initialize menus.  Tell TransSkel to process the Apple menu}
  126. {    automatically, and associate the proper procedures with the}
  127. {    File and Edit menus.}
  128.  
  129.     procedure SetUpMenus;
  130.  
  131.     begin
  132.         SkelApple('About Skel…', @DoAbout);
  133.         fileMenu := GetMenu(fileMenuRes);
  134.         dummy := SkelMenu(fileMenu, @DoFileMenu, nil, true);
  135.     end;
  136.  
  137. { -------------------------------------------------------------------- }
  138. {                    Window handling procedures                            }
  139. { -------------------------------------------------------------------- }
  140.  
  141.     procedure WindActivate (active: Boolean);
  142.  
  143.     begin
  144.         DrawGrowIcon(theWind);    { make grow box reflect new window state }
  145.     end;
  146.  
  147. {    On update event, can ignore the resizing information, since the whole}
  148. {    window is always redrawn in terms of the current size, anyway.}
  149. {    Content area is dark gray except scroll bar areas, which are white.}
  150. {    Draw grow box as well.}
  151.  
  152.     procedure WindUpdate (resized: Boolean);
  153.  
  154.         var
  155.             r: Rect;
  156.  
  157.     begin
  158.         r := theWind^.portRect;        { paint window dark gray }
  159.         r.bottom := r.bottom - 15;            { don't bother painting the }
  160.         r.right := r.right - 15;            { scroll bar areas }
  161. {$IFC UNDEFINED THINK_PASCAL}
  162.         FillRect(r, qd.dkGray);
  163. {$ELSEC}
  164.         FillRect(r, dkGray);
  165. {$ENDC}
  166.         r := theWind^.portRect;    { paint scroll bar areas white }
  167.         r.left := r.right - 15;
  168. {$IFC UNDEFINED THINK_PASCAL}
  169.         FillRect(r, qd.white);
  170. {$ELSEC}
  171.         FillRect(r, white);
  172. {$ENDC}
  173.         r := theWind^.portRect;
  174.         r.top := r.bottom - 15;
  175. {$IFC UNDEFINED THINK_PASCAL}
  176.         FillRect(r, qd.white);
  177. {$ELSEC}
  178.         FillRect(r, white);
  179. {$ENDC}
  180.         DrawGrowIcon(theWind);
  181.     end;
  182.  
  183.     procedure WindHalt;
  184.  
  185.     begin
  186.         CloseWindow(theWind);
  187.     end;
  188.  
  189. {    Read window from resource file and install handler for it.  Mouse}
  190. {    and key clicks are ignored.  There is no close proc since the window}
  191. {    doesn't have a close box.  There is no idle proc since nothing is}
  192. {    done while the window is in front (all the things that are done are}
  193. {    handled by TransSkel).}
  194.  
  195.     procedure WindInit;
  196.  
  197.     begin
  198.         theWind := GetNewWindow(theWindRes, nil, WindowPtr(-1));
  199.         SetPort(theWind);
  200.         dummy := SkelWindow(theWind, nil, nil, @WindUpdate, @WindActivate, nil, @WindHalt, nil, false);
  201.     end;
  202.  
  203. { -------------------------------------------------------------------- }
  204. {                                    Main                                }
  205. { -------------------------------------------------------------------- }
  206.  
  207.  
  208. begin
  209.     SkelInit(6, nil);                { initialize }
  210.     SetUpMenus;                { install menu handlers }
  211.     WindInit;                    { install window handler }
  212.     SkelMain;                { loop 'til Quit selected }
  213.     SkelClobber;                { clean up }
  214. end.